//
//  JZHDetailsViewController.m
//  极致荟
//
//  Created by hetao on 14-5-15.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHDetailsViewController.h"
#import "JZHDetailsSetViewController.h"
#import "JZHChatViewController.h"
#import "JZHPersonaldetailsViewController.h"
@interface JZHDetailsViewController ()
{
    BOOL isfriend;
}
@property (weak, nonatomic) IBOutlet UILabel *adders;
@property (weak, nonatomic) IBOutlet UITextView *content;
@property (weak, nonatomic) IBOutlet UIButton *xb;
@property (weak, nonatomic) IBOutlet UIButton *rethbut;
@property (weak, nonatomic) IBOutlet UIImageView *rethimage;

@end

@implementation JZHDetailsViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];

    if(self.ouser.isAs)
    {
        self.xb.hidden=NO;
    }else
    {
        self.xb.hidden=YES;
    }
}
- (id)initOthUser:(OtherUsers *)ouser
{
    self=[[JZHDetailsViewController alloc] init];
    self.ouser=ouser;
    return self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [_headimge.layer setCornerRadius:4.0];
    [_headimge.layer setMasksToBounds:YES];
    [_headimge.layer setBorderWidth:1];
    [_headimge.layer setBorderColor:[[UIColor whiteColor]CGColor]];
    [ImageCache imageUrl:self.ouser.userHeadImage UiImageview:self.headimge];
    self.ousername.text=self.ouser.name;
    [self httpData];
    [self vipiconimage];
}

//会员图标显示设置
- (void)vipiconimage
{
    int vip=self.ouser.vip;
    if(vip==0)
    {
        if(self.ouser.sex==1)
        {
            self.vipicon.image=[UIImage imageNamed:@"no1-1"];
        }else
        {
            self.vipicon.image=[UIImage imageNamed:@"no0-1"];
        }
        
        return;
    }
    
    if(vip==1)
    {
        self.vipicon.image=[UIImage imageNamed:@"vip1-1"];
    }else
    {
        self.vipicon.image=[UIImage imageNamed:@"vip2-1"];
    }
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    [self.navigationController setNavigationBarHidden:NO];
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)httpData
{
    NSDictionary *dic=[[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:[User defuceUser].userId],@"userId",[NSNumber numberWithInt:self.ouser.userId],@"friendsId", nil];
    [HttpRequest httpRequestPost:JZHHTTPURL(@"asterisk/friendsInformation") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        if(rerurncode==0)
        {
            NSLog(@"%@",data);
            NSDictionary *arrs=[[data objectForKey:@"data"] objectForKey:@"list"];
            if([arrs objectForKey:@"cityName"]!=[NSNull null] && [arrs objectForKey:@"areaName"]!=[NSNull null])
            {
             self.adders.text=[[arrs objectForKey:@"cityName"] stringByAppendingFormat:@" %@",[arrs objectForKey:@"areaName"]];
            }else
            {
                self.adders.text=@"未知";
            }
           
            self.content.text=[arrs objectForKey:@"signature"];
            if([[arrs  objectForKey:@"asterisk"] intValue]==0)
            {
                self.xb.hidden=YES;
            }else
            {
                self.xb.hidden=NO;
            }
            if([[arrs objectForKey:@"isFriend"] intValue]==0)
            {
                self.rethbut.hidden=YES;
                self.rethimage.hidden=YES;
            }else
            {
                self.rethbut.hidden=NO;
                self.rethimage.hidden=NO;
            }
            [ImageCache imageUrl:[[[data objectForKey:@"data"] objectForKey:@"imgPrefix"] stringByAppendingString:[arrs  objectForKey:@"userAvatar"]] UiImageview:self.headimge];
            self.ousername.text=[arrs objectForKey:@"userName"];
            [self addimageData:[arrs objectForKey:@"userImage"] pathHead:[[data objectForKey:@"data"] objectForKey:@"imgPrefix"]];
            if([arrs objectForKey:@"remark"] ==[NSNull null] ||[[arrs objectForKey:@"remark"] intValue]==0)
            {
                self.ouser.bname=@"";
            }else
            {
                self.ouser.bname=[arrs objectForKey:@"remark"];
            }
            
        }
    }];
}

- (void)addimageData:(NSArray *)arr pathHead:(NSString *)str
{
    if(arr)
    {
        if(arr.count!=0)
        {
            for(int i=0;i<arr.count;i++)
            {
                UIImageView *iv=[[UIImageView alloc] initWithFrame:CGRectMake(i*50+(i*15), 0, 58, 58)];
                
                [ImageCache imageUrl:[str stringByAppendingString: arr[i] ] UiImageview:iv];
                [self.imagev addSubview: iv];
            }
        }
    }
}
- (IBAction)pop:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)pus:(id)sender {
    [self.navigationController pushViewController:[[JZHDetailsSetViewController alloc]initOuser:self.ouser] animated:YES];
}
- (IBAction)pusmessge:(id)sender {

    [self.navigationController pushViewController:[[JZHChatViewController alloc]initOuser:self.ouser Recommend:nil]
                                         animated:YES];
}

- (IBAction)puspolt:(id)sender {
    
    [self.navigationController pushViewController:[JZHPersonaldetailsViewController shareName:self.ouser] animated:YES];
    
}
@end
